package stage_1_module_4.code.homework_5;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

public class Server {
    public static List<Socket> sht = new ArrayList<>();
    public static void main(String[] args) {
        ServerSocket ss = null;
        Socket s = null;
        try {
            ss = new ServerSocket(8899);
            System.out.println("服务端启动");
            while(true) {
                s = ss.accept();
                sht.add(s);
                ServerThread st = new ServerThread(s,sht);
                st.start();
            }

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            // 4.关闭Socket并释放有关的资源
            if (null != ss) {
                try {
                    ss.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
